﻿CREATE TABLE [dbo].[RulajeDoc] (
    [IDDocument]       BIGINT          IDENTITY (1, 1) NOT NULL,
    [ValoareLei]       DECIMAL (20, 2) CONSTRAINT [DF_RulajeDoc_ValoareLei] DEFAULT ((0)) NOT NULL,
    [ValoareValuta]    DECIMAL (20, 2) CONSTRAINT [DF_RulajeDoc_ValoareValuta] DEFAULT ((0)) NOT NULL,
    [NumarDoc]         DECIMAL (18)    CONSTRAINT [DF_RulajeDoc_NumarDoc] DEFAULT ((0)) NOT NULL,
    [DataDoc]          DATETIME        CONSTRAINT [DF_RulajeDoc_DataDoc] DEFAULT (getdate()) NOT NULL,
    [NumarNota]        VARCHAR (50)    CONSTRAINT [DF_RulajeDoc_NumarNota] DEFAULT ('') NOT NULL,
    [TipFormula]       SMALLINT        CONSTRAINT [DF_RulajeDoc_TipFormula] DEFAULT ((0)) NOT NULL,
    [IDJurnal]         INT             CONSTRAINT [DF_RulajeDoc_IDJurnal] DEFAULT ((0)) NULL,
    [Observatii]       VARCHAR (200)   NULL,
    [xUser]            VARCHAR (50)    CONSTRAINT [DF_RulajeDoc_xUser] DEFAULT (suser_sname()) NOT NULL,
    [xHost]            VARCHAR (50)    CONSTRAINT [DF_RulajeDoc_xHost] DEFAULT (host_name()) NOT NULL,
    [xDate]            DATETIME        CONSTRAINT [DF_RulajeDoc_xDate] DEFAULT ((0)) NOT NULL,
    [CodUnitate]       SMALLINT        CONSTRAINT [DF_RulajeDoc_CodUnitate] DEFAULT ((0)) NOT NULL,
    [IDSursaFinantare] SMALLINT        NULL,
    [IDSectorBugetar]  SMALLINT        NULL,
    CONSTRAINT [PK_RulajeDoc] PRIMARY KEY CLUSTERED ([IDDocument] ASC) WITH (FILLFACTOR = 90),
    CONSTRAINT [CK_RulajeDoc_Tip_FORMULA] CHECK ([TipFormula]=(3) OR ([TipFormula]=(2) OR ([TipFormula]=(1) OR [TipFormula]=(0)))),
    CONSTRAINT [FK_RulajeDoc_Jurnale] FOREIGN KEY ([IDJurnal]) REFERENCES [dbo].[Jurnale] ([IDJurnal]),
    CONSTRAINT [FK_RulajeDoc_SectorBugetar] FOREIGN KEY ([IDSectorBugetar]) REFERENCES [dbo].[SectorBugetar] ([IDSectorBugetar]),
    CONSTRAINT [FK_RulajeDoc_SursaFinantare] FOREIGN KEY ([IDSursaFinantare]) REFERENCES [dbo].[SurseFinantare] ([IDSursaFinantare]),
    CONSTRAINT [FK_RulajeDoc_Unitati] FOREIGN KEY ([CodUnitate]) REFERENCES [dbo].[Unitati] ([CodUnitate])
);


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Data la cre s-a editat', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'RulajeDoc', @level2type = N'COLUMN', @level2name = N'xDate';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Calculatorul de pe care s-a lucrat', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'RulajeDoc', @level2type = N'COLUMN', @level2name = N'xHost';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Utilizatorul care a editat nota contabila', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'RulajeDoc', @level2type = N'COLUMN', @level2name = N'xUser';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'id-ul jurnalului de care apartine inregistrarea', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'RulajeDoc', @level2type = N'COLUMN', @level2name = N'IDJurnal';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Tipul formulei', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'RulajeDoc', @level2type = N'COLUMN', @level2name = N'TipFormula';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Numarul notei de care apartine formula', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'RulajeDoc', @level2type = N'COLUMN', @level2name = N'NumarNota';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Data Notei Contabile', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'RulajeDoc', @level2type = N'COLUMN', @level2name = N'DataDoc';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Numarul Formulei Contabile', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'RulajeDoc', @level2type = N'COLUMN', @level2name = N'NumarDoc';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Valoarea totala in valuta', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'RulajeDoc', @level2type = N'COLUMN', @level2name = N'ValoareValuta';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Valoarea totala a documentului in lei', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'RulajeDoc', @level2type = N'COLUMN', @level2name = N'ValoareLei';

